import { mapState, mapMutations } from 'vuex'
export default {
	name: 'EventSource',
	data() {
		return {
			messageList:[],
		}
	},
	computed: {
		...mapState([
			'token'
		]),
	},
	methods: {
		...mapMutations([
			'TOKEN'
		]),
		connectEventSource(){
			var source = new EventSource('eventSourceTest');
			console.log(source)
			source.onopen = function(e){
				console.log("链接成功")
				console.log(e)
			}
			source.onmessage = function(e){
				console.log("收到消息")
				this.messageList.push(e.data)
			}
			source.error = function(e){
				console.log("链接失败")
				console.log(e)
			}
		},
	},
	components: {

	},
	created() {
		document.title = "EventSource";
		if(window.EventSource){
			this.connectEventSource();
		}else{
			alert("对不起，您的浏览器不支持EventSource")
		}
		
	}
}